package com.ysd.crm.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Table
@Getter
@Setter
@NoArgsConstructor//无参构造
@AllArgsConstructor//全参构造
public class Modules {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String title;//标题
	public Modules(Integer id, String title,  Integer parentId, String checkArr) {
		super();
		this.id = id;
		this.title = title;
		this.parentId = parentId;
		this.checkArr = checkArr==null?"0":"1";
	}
	private String details;//介绍
	private String url;//页面路径
	private Integer parentId;//父节点id
	@Transient //临时字段，不对应数据库
	private String checkArr="0";//节点选中状态，0表示未选中，1表示选中
	@JsonIgnore
	@ManyToMany
	@Cascade(CascadeType.SAVE_UPDATE)
	@JoinTable(name="role_module_tb",joinColumns = @JoinColumn(name="module_id"),inverseJoinColumns = @JoinColumn(name="role_id"))
	@NotFound(action = NotFoundAction.IGNORE)//找不到外键引用时忽略
	private Set<Roles> roleSet = new HashSet<Roles>();
}
